package toanstt.com.MatchUp;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

public class TBitmap2 
{
	int rows;
	int cols;
	public int n;
	public int index = 0;
	public Bitmap[] bitmap;
	public int width,height;
	public int halfwidth,halfheight;
	public TBitmap2 (String filename,int row,int col,int newwidth)
	{
		Bitmap bitmaps = T.loadImageFromAsset(filename);
		n=row*col;
		
		Paint mainPaint= new Paint(); 
		mainPaint.setAntiAlias(true);
		mainPaint.setFilterBitmap(true);
		mainPaint.setDither(true);
		
		//mainCanvas.drawBitmap(backgroundImage, matrix, mainPaint); 
		
		float dcol =bitmaps.getWidth()*1.0f/col;
		float drow =bitmaps.getHeight()*1.0f/row;
		
		float scale = newwidth*1.0f/dcol;
		height = (int)(scale*drow);
		bitmap = new Bitmap[n];
		for(int i=0;i<row;i++)
		{
			for(int j=0;j<col;j++)
			{
				  
				
				  bitmap[i*col+j] =Bitmap.createBitmap(bitmaps, (int)(j*dcol), (int)(i*drow), (int)(dcol), (int)(drow));
				  bitmap[i*col+j] = Bitmap.createScaledBitmap(bitmap[i*col+j], newwidth, height, false);
			}
		}
		bitmaps = null;
		width = newwidth;
		halfwidth = width/2;
		halfheight = height/2;
	}
	public TBitmap2 (String filename,int row,int col,int newheigh,boolean a123)
	{
		Bitmap bitmaps = T.loadImageFromAsset(filename);
		n=row*col;
		
		
		float dcol =bitmaps.getWidth()*1.0f/col;
		float drow =bitmaps.getHeight()*1.0f/row;
		
		float scale = newheigh*1.0f/drow;
		width = (int)(scale*dcol);
		bitmap = new Bitmap[n];
		for(int i=0;i<row;i++)
		{
			for(int j=0;j<col;j++)
			{
				  
				  bitmap[i*col+j] =Bitmap.createBitmap(bitmaps, (int)(j*dcol), (int)(i*drow), (int)(dcol), (int)(drow));
				  bitmap[i*col+j] = Bitmap.createScaledBitmap(bitmap[i*col+j], width, newheigh, false);
			}
		}
		bitmaps = null;
		height = newheigh;
		halfwidth = width/2;
		halfheight = height/2;
	}
	public TBitmap2(String filename, int row, int col, int dISPLAY_WIDTH, int dISPLAY_HEIGHT) 
	{
		Bitmap bitmaps = T.loadImageFromAsset(filename);
		n=row*col;
		
		
		float dcol =bitmaps.getWidth()*1.0f/col;
		float drow =bitmaps.getHeight()*1.0f/row;
		
		float scale = dISPLAY_HEIGHT*1.0f/drow;
		width = (int)(scale*dcol);
		bitmap = new Bitmap[n];
		for(int i=0;i<row;i++)
		{
			for(int j=0;j<col;j++)
			{
				  
				  bitmap[i*col+j] =Bitmap.createBitmap(bitmaps, (int)(j*dcol), (int)(i*drow), (int)(dcol), (int)(drow));
				  bitmap[i*col+j] = Bitmap.createScaledBitmap(bitmap[i*col+j], dISPLAY_WIDTH, dISPLAY_HEIGHT, false);
			}
		}
		bitmaps = null;
		height = dISPLAY_HEIGHT;
		width = dISPLAY_WIDTH;
		halfwidth = width/2;
		halfheight = height/2;
	}
	public void Draw_IndexBitmap(Canvas canvas)
	{
		//canvas.drawBitmap(bitmap, matrix, paint)
	}
	
}
